﻿
namespace Oddo.Concept.Crm.Client
{
    using System;
    using System.Windows;
    using Microsoft.Practices.Prism.UnityExtensions;
    using Microsoft.Practices.Unity;
    using Oddo.Concept.Crm.Client.ViewModels;
    using Oddo.Concept.Crm.Client.Views;
    using Oddo.Concept.Crm.Common.Presentation;
    using Oddo.Concept.Crm.Common.Presentation.Interfaces;

    public class ApplicationBootStrapper : DefaultBootStrapper
    {
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
            this.Container.RegisterType<IShellView, Shell>(new ContainerControlledLifetimeManager());
            this.Container.RegisterType<ShellViewModel>();
        }

        protected override DependencyObject CreateShell()
        {
            return this.Container.Resolve<IShellView>() as Shell;
        }
        
        public override void AfterShellInitialized()
        {
        }

        public override void ModulesInitializationCompleted()
        {
            var view = this.Container.TryResolve<IShellView>() as Shell;
            if (view == null) throw new ArgumentException("Cannot resolve instance of type IShellView");

            Application.Current.MainWindow = view;
            Application.Current.MainWindow.Show();
        }
    }
}